Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@react-stately/tree

Package Overview
Dependencies
Maintainers
2
Versions
826
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-stately/tree

Spectrum UI components in React

  • 3.8.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.1M
increased by15.18%
Maintainers
2
Weekly downloads
 
Created

What is @react-stately/tree?

@react-stately/tree is a library for managing state in tree-like structures in React applications. It provides hooks and utilities to handle tree data, selection, expansion, and other common tree operations.

What are @react-stately/tree's main functionalities?

Tree Data Management

This feature allows you to manage tree data structures. The `useTreeState` hook initializes the tree state with the given tree data and selection mode.

import { useTreeState } from '@react-stately/tree';

const tree = {
  name: 'root',
  children: [
    { name: 'child 1' },
    { name: 'child 2', children: [{ name: 'grandchild 1' }] }
  ]
};

const state = useTreeState({
  tree,
  selectionMode: 'multiple'
});

console.log(state.collection);

Selection Management

This feature allows you to manage selection within the tree. The `selectionManager` provides methods to toggle selection and access selected keys.

import { useTreeState } from '@react-stately/tree';

const tree = {
  name: 'root',
  children: [
    { name: 'child 1' },
    { name: 'child 2', children: [{ name: 'grandchild 1' }] }
  ]
};

const state = useTreeState({
  tree,
  selectionMode: 'multiple'
});

state.selectionManager.toggleSelection('child 1');
console.log(state.selectionManager.selectedKeys);

Expansion Management

This feature allows you to manage the expansion state of tree nodes. The `expansionManager` provides methods to toggle expansion and access expanded keys.

import { useTreeState } from '@react-stately/tree';

const tree = {
  name: 'root',
  children: [
    { name: 'child 1' },
    { name: 'child 2', children: [{ name: 'grandchild 1' }] }
  ]
};

const state = useTreeState({
  tree,
  selectionMode: 'multiple'
});

state.expansionManager.toggleExpansion('child 2');
console.log(state.expansionManager.expandedKeys);

Other packages similar to @react-stately/tree

FAQs

Package last updated on 21 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc